import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './permission'
import 'amfe-flexible'
import { Button, NavBar, Field, Toast, Tabbar, TabbarItem, Search, Tab, Tabs, Cell, PullRefresh, ActionSheet, Sticky, List, Skeleton, CellGroup, Image as VanImage, Dialog, ShareSheet, Row, Col, Badge, Divider, Tag, Popup } from 'vant'
// 登录
import { Form } from 'vant'

// 图标
import { Icon } from 'vant'
import '@/directive/index.js'

Vue.use(Button)
Vue.use(NavBar)
Vue.use(Form)
Vue.use(Field)

Vue.use(Toast)

Vue.use(Tabbar)
Vue.use(TabbarItem)
Vue.use(Icon)

Vue.use(Search)
Vue.use(Tab)
Vue.use(Tabs)
Vue.use(Cell)
Vue.use(PullRefresh)
Vue.use(ActionSheet)
Vue.use(Sticky)
Vue.use(List)
Vue.use(Skeleton)
Vue.use(CellGroup)

Vue.use(VanImage)
// 全局注册
Vue.use(Dialog)
Vue.use(Row)
Vue.use(Col)
Vue.use(Badge)

Vue.use(ShareSheet)
Vue.use(Divider)

Vue.use(Tag)

import { Uploader } from 'vant';

Vue.use(Uploader);
import { DatetimePicker } from 'vant';

Vue.use(DatetimePicker);

// import './perimosei'

//全局局部组件
import Articles from './views/Home/components/articles.vue'
Vue.component(Articles.name, Articles)
// 注册一个全局自定义指令 `v-focus`
Vue.directive('focus', {
  // 当被绑定的元素插入到 DOM 中时……
  inserted: function (el) {
    // 聚焦元素
    el.querySelector('.van-field__control').focus()
  }
})

Vue.use(Popup)
// 路由守卫
// router.beforeEach((to, from, next) => {
//   const isLogin = window.localStorage.getItem('token')
//   if (isLogin) {
//     // 如果用户信息存在则往下执行。
//     next()
//   } else {
//     // 如果用户token不存在则跳转到login页面
//     if (to.path === '/login') {
//       next()
//     } else {
//       Toast.fail('请登录')
//       next('/login')
//     }
//   }
// })

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
